package com.demo.apparel.service.uniapp.Impl;

import com.demo.apparel.entity.Category;
import com.demo.apparel.mapper.uniapp.WxCategoryMapper;
import com.demo.apparel.service.uniapp.WxCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class WxCategoryServiceImpl implements WxCategoryService {

    @Autowired
    private WxCategoryMapper wxCategoryMapper;

    @Override
    public Map<String, String> getCategoryMap() {
        List<Category> list = wxCategoryMapper.getCategoryMap();
        return list.stream()
                .collect(Collectors.toMap(
                        c -> String.valueOf(c.getCategory()),
                        Category::getCategoryName
                ));
    }

    @Override
    public List<Map<String, String>> listForSelect() {
        List<Category> categories = wxCategoryMapper.selectList(null);

        return categories.stream().map(c -> {
            Map<String, String> map = new HashMap<>();
            map.put("label", c.getCategoryName());
            map.put("value", String.valueOf(c.getCategory()));
            return map;
        }).collect(Collectors.toList());
    }
}

